using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.StylusInput;
using Microsoft.StylusInput.PluginData;
using System.Windows.Forms;
using System.Drawing;


namespace MultiLayer
{
    public abstract class Tool : IStylusAsyncPlugin
    {
        protected Tool(Control pContainer)
        {
            this.mContainer = pContainer;
        }

        public Cursor Cursor
        {
            get
            {
                return this.mCursor;
            }
        }

        virtual public DataInterestMask DataInterest
        {
            get
            {
                return DataInterestMask.Packets | DataInterestMask.InAirPackets | DataInterestMask.StylusDown | DataInterestMask.StylusUp;
            }
        }

        virtual public void InAirPackets(RealTimeStylus sender, InAirPacketsData data)
        {
        }

        virtual public void Packets(RealTimeStylus sender, PacketsData data)
        {
        }

        virtual public void StylusDown(RealTimeStylus sender, StylusDownData data)
        {
        }

        virtual public void StylusUp(RealTimeStylus sender, StylusUpData data)
        {
        }

        #region Unused IStylusAsyncPlugin Members

        public void CustomStylusDataAdded(RealTimeStylus sender, CustomStylusData data) { }
        public void Error(RealTimeStylus sender, ErrorData data) { }
        public void RealTimeStylusDisabled(RealTimeStylus sender, RealTimeStylusDisabledData data) { }
        public void RealTimeStylusEnabled(RealTimeStylus sender, RealTimeStylusEnabledData data) { }
        public void StylusButtonDown(RealTimeStylus sender, StylusButtonDownData data) { }
        public void StylusButtonUp(RealTimeStylus sender, StylusButtonUpData data) { }
        public void StylusInRange(RealTimeStylus sender, StylusInRangeData data) { }
        public void StylusOutOfRange(RealTimeStylus sender, StylusOutOfRangeData data) { }
        public void SystemGesture(RealTimeStylus sender, SystemGestureData data) { }
        public void TabletAdded(RealTimeStylus sender, TabletAddedData data) { }
        public void TabletRemoved(RealTimeStylus sender, TabletRemovedData data) { }
        
        #endregion

        protected void StartDrawing()
        {
            this.mGraphics = this.mContainer.CreateGraphics();
            this.mGraphics.PageScale = 0.01f;
            this.mGraphics.PageUnit = GraphicsUnit.Millimeter;
            this.mGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        }

        protected void FinishDrawing()
        {
            this.mGraphics.Dispose();
            this.mGraphics = null;
        }

        protected void RefreshScreen(Rectangle pRectangle)
        {
            this.mContainer.Invalidate();
        }

        protected Control mContainer;
        protected Cursor mCursor;
        protected Graphics mGraphics;
    }
}
